package com.example.dbdoc.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 索引信息模型
 * 
 * @author 系统生成
 * @version 1.0.0
 */
public class IndexInfo {
    
    /** 索引名 */
    private String indexName;
    
    /** 索引类型 (PRIMARY, UNIQUE, INDEX) */
    private String indexType;
    
    /** 索引字段列表 */
    private List<String> columns;
    
    /** 字段在索引中的序号 */
    private int sequence;
    
    /** 是否唯一索引 */
    private boolean unique;
    
    public IndexInfo() {
        this.columns = new ArrayList<>();
    }
    
    public IndexInfo(String indexName, String indexType, boolean unique) {
        this();
        this.indexName = indexName;
        this.indexType = indexType;
        this.unique = unique;
    }
    
    // Getter和Setter方法
    public String getIndexName() {
        return indexName;
    }
    
    public void setIndexName(String indexName) {
        this.indexName = indexName;
    }
    
    public String getIndexType() {
        return indexType;
    }
    
    public void setIndexType(String indexType) {
        this.indexType = indexType;
    }
    
    public List<String> getColumns() {
        return columns;
    }
    
    public void setColumns(List<String> columns) {
        this.columns = columns;
    }
    
    public int getSequence() {
        return sequence;
    }
    
    public void setSequence(int sequence) {
        this.sequence = sequence;
    }
    
    public boolean isUnique() {
        return unique;
    }
    
    public void setUnique(boolean unique) {
        this.unique = unique;
    }
    
    // 便利方法
    public void addColumn(String columnName) {
        this.columns.add(columnName);
    }
    
    /**
     * 获取索引类型的中文描述
     */
    public String getIndexTypeDescription() {
        switch (indexType.toUpperCase()) {
            case "PRIMARY":
                return "主键";
            case "UNIQUE":
                return "唯一索引";
            case "INDEX":
            case "NORMAL":
                return "普通索引";
            default:
                return indexType;
        }
    }
    
    /**
     * 获取索引的显示名称
     */
    public String getDisplayName() {
        if ("PRIMARY".equalsIgnoreCase(indexType)) {
            return "PRIMARY";
        }
        return indexName;
    }
    
    @Override
    public String toString() {
        return "IndexInfo{" +
                "indexName='" + indexName + '\'' +
                ", indexType='" + indexType + '\'' +
                ", columns=" + columns +
                ", sequence=" + sequence +
                ", unique=" + unique +
                '}';
    }
}